import React from "react";
import PropTypes from "prop-types";
import { withRouter } from "react-router-dom";

class ScrollToTop extends React.Component {
    static propTypes = {
        location: PropTypes.object.isRequired,
        children: PropTypes.node.isRequired
    };

    componentDidUpdate(prevProps) {
        if (this.props.location !== prevProps.location) {
            window.scroll(0, 0);
        }
    }

    render() {
        const { children } = this.props;

        return <React.Fragment>{children}</React.Fragment>;
    }
}

export default withRouter(ScrollToTop);
